package com.handpay.nocardpay.baselibrary.raindrops;

import com.handpay.nocardpay.baselibrary.logutils.HPLog;
import com.handpay.nocardpay.baselibrary.utils.MD5;

import java.util.Map;

/**
 * Created by sxshi on 2018-4-23.
 */

public class RainDropsSign {

    /**
     * 获取签名
     *
     * @param param 需要签名的参数
     * @return 签名
     */
    public static String getSign(Map<String, Object> param) {
        if (param.isEmpty()) {
            return null;
        }
        StringBuilder stringBuilder = new StringBuilder();
        for (Map.Entry<String, Object> entry : param.entrySet()) {
            stringBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
        }
        String sign = stringBuilder.deleteCharAt(stringBuilder.length() - 1).toString();
        HPLog.d(HPLog.SSX_TAG, sign);
        return MD5.toMD5(sign).toLowerCase();
    }

    /**
     * 生成签名
     * @param channelCode 渠道
     * @param mobile 手机
     * @param name 姓名
     * @return MD5字符
     */
    public static String getSign(String channelCode, String mobile, String name) {
        String sign = "channelCode=" + channelCode + "&mobile=" + mobile + "&name=" + name;
        return MD5.toMD5(sign).toLowerCase();
    }

    /**
     * 生成签名
     * @param xrId
     * @return
     */
    public static String getXrIdSign(String xrId){
        String sign="xrId="+xrId;
        return MD5.toMD5(sign).toLowerCase();
    }
}
